J2EE Connector Architecture Resource Adapter
The J2EE Connector Architecture defines a standard structure for connecting the J2EE platform to Enterprise Information Systems (EIS). Examples of EIS include mainframe transaction processing, database systems, and legacy applications that are not written in the Java programming language. The J2EE Connector Architecture allows you to integrate EIS with application servers and enterprise applications. The J2EE Connector Architecture defines a standard set of system-level contracts between an application server and the EIS to ensure compatibility between them. The resource adapter implements the EIS portion of these system-level contracts.
The J2EE Connector Architecture also defines a standard Service Provider Interface (SPI) for integrating the transaction, security and connection management facilities of an application server with those of a transactional resource manager. The JDBC specification provides more information about the relationship of JDBC to the SPI specified in the J2EE Connector Architecture.
The JDBC driver supports JDBC functionality through the J2EE Connector Architecture SPI by providing resource adapters. A resource adapter is a system-level software driver used by an application server to connect to an EIS. The resource adapter communicates with the server to provide the underlying transaction, security, and connection pooling mechanisms.
The SequeLink resource adapter conforms to the J2EE Connector Architecture 1.0 specification. The resource adapter is provided in a resource archive (RAR) file, sljc.rar. Refer to the SequeLink Installation Guide for information about creating the resource adapter.
Using the Resource Adapter with an Application Server
The SequeLink resource adapter can be used with any J2EE 1.3 or higher application server. To use the resource adapter with J2EE 1.4 or higher application servers, it must be used in conjunction with the Sun Microsystems JDBC Connector. Refer to the Sun Microsystems JDBC Connector documentation for more information or see the following Web site:
http://java.sun.com/developer/earlyAccess/jdbc/index.html
In an application server environment, the resource adapter is deployed using a deployment tool. Each RAR file includes a deployment descriptor, which instructs the application server about how to use the resource adapter in an application server environment. The deployment descriptor contains information about the resource adapter, including security and transactional capabilities, and the ManagedConnectionFactory class name. Refer to your application server documentation for details about how to deploy components using the deployment tool.
Using the Resource Adapter from an Application
The JCA resource adapter may also be used directly from an application, rather than through a container-managed, application server environment. The following code example shows how you might access a database using the resource adapter:
package examples; import java.util.Hashtable; import java.sql.Connection; import javax.sql.DataSource; import javax.naming.*; import javax.resource.spi.*; import com.ddtek.resource.sljdbc.JCAConnectionFactory; import com.ddtek.resource.sljdbc.spi.*; public class RAExample { static public void main(String[] args) { try { // Create a connection factory instance SequeLinkManagedConnectionFactory managedFactory = new SequeLinkManagedConnectionFactory(); managedFactory.setServerName("MyOracleServer"); managedFactory.setPortNumber("1521"); JCAConnectionFactory factory = (JCAConnectionFactory) managedFactory.createConnectionFactory(); // Get an InitialContext. Using File System JNDI Service // Provider as an example Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:c:/ConnectionFactories"); Context connectorContext = new InitialContext(env); // Bind the connection factory try { connectorContext.bind("ConnectionFactory", factory); } catch (NameAlreadyBoundException except) { connectorContext.rebind("ConnectionFactory", factory); } } catch (Exception except) { System.out.println("Error creating DataSource"); System.exit(0); } // Connect via the DataSource try { // Get an InitialContext. Using File System JNDI Service // Provider as an example Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:c:/ConnectionFactories"); Context connectorContext = new InitialContext(env); // Lookup the connection factory DataSource dataSource = (DataSource) connectorContext.lookup("ConnectionFactory"); Connection connection =dataSource.getConnection("scott", "tiger"); catch (Exception except) { System.out.println("Error looking up connection factory"); } } }